package com.jee.project.model;

import javax.persistence.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Positive;
import javax.validation.constraints.Size;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jee.project.model.validation.OnCreate;
import com.jee.project.model.validation.OnEdit;

import java.util.Collection;
import java.util.HashSet;

@Entity
@Table(name="college")
public class College {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id")
    @Null(groups= OnCreate.class, message="创建学院时不用指定id值")
    @NotNull(groups= OnEdit.class, message="修改学院时id不能为空")
    @Positive
    private Long id;
    @NotBlank
    @Size(min=2,max=20)
    @Column(name="name", nullable=false)
    private String name;

    @OneToMany(mappedBy="college",fetch = FetchType.LAZY)
    @JsonIgnore
    private Collection<Course> courses = new HashSet<Course>();
    public Collection<Course> getCourses() {
        return courses;
    }
    public void setCourses(Collection<Course> courses) {
        this.courses = courses;
    }
    public College() { // 无参数构造函数在Entity中是必须的
        super();
    }
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
